package haw.pr2.A3.implementations;

import java.util.Iterator;
import haw.pr2.A3.interfaces.*;
import java.util.Collection;
import java.util.Set;
import static haw.pr2.A3.implementations.UtilityclassValues.*;
import static haw.pr2.A3.implementations.Entities.*;

/**
 *
 * @author Fabian Heidorn, Alexander Kaack
 */
class PalletStowageImpl implements Stowage<Pallet> {

        
     Bounded3DimStackImpl<Pallet> palletStack;
    
    Mass emptyMass, maxMass;
    BoundingBox bBox;
    
    
    private PalletStowageImpl(int bay, int row, int tier) {
         palletStack=(Bounded3DimStackImpl<Pallet>) Bounded3DimStackImpl.valueOf(bay, row, tier, nullPallet());
         emptyMass=ZERO_MASS;
         maxMass=ZERO_MASS.add(PAL_MAX_MASS.mul(bay*row*tier));
         //bBox berechnen
    }
    
    public static PalletStowageImpl valueOf(int bay, int row, int tier) {
        return new PalletStowageImpl(bay, row, tier);
    } 

    @Override
    public Mass mass() {
        Mass res = ZERO_MASS;
        Set<Pallet> pallets = this.getAll();
        for (Iterator<Pallet> it = pallets.iterator(); it.hasNext();) {
            Pallet pal = it.next();
            res.add(pal.mass());
        }
        return res;
    }

    @Override
    public BoundingBox boundingBox() {
        Set<Pallet> pallet=this.getAll();
        return EMPTY_BOUNDING_BOX.addAll(pallet);
    }

    @Override
    public Mass emptyMass() {
        return ZERO_MASS;
    }

    @Override
    public Mass maxMass() {
        return new MassInKg(Long.MAX_VALUE);
    }

    @Override
    public boolean isEmpty() {
        return palletStack.isEmpty();
    }

    @Override
    public boolean isFull() {
        return palletStack.isFull();
    }

    @Override
    public void load(int bayNo, int rowNo, Pallet elem) {
        palletStack.load(bayNo, rowNo, elem);
    }

    @Override
    public void load(Pallet elem) {
        palletStack.load(elem);
    }

    @Override
    public void loadAll(Collection<Pallet> coll) {
        palletStack.loadAll(coll);
    }

    @Override
    public boolean tierIsEmpty(int bay, int row) {
        return palletStack.tierIsEmpty(bay, row);
    }

    @Override
    public boolean tierIsFull(int bay, int row) {
        return palletStack.tierIsFull(bay, row);
    }

    @Override
    public boolean contains(Object elem) {
        return palletStack.contains(elem);
    }

    @Override
    public boolean containsAll(Collection<?> coll) {
        return palletStack.containsAll(coll);
    }

    @Override
    public Pallet get(StowageLocation loc) {
        return palletStack.get(loc);
    }

    @Override
    public Set<Pallet> getAll() {
        return palletStack.getAll();
    }

    @Override
    public StowageLocation locationOf(Pallet elem) {
        return palletStack.locationOf(elem);
    }
 
}
